home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!tglbbs!charles.herold
- From: charles.herold@tglbbs.com (Charles Herold)
- Newsgroups: comp.lang.c
- Subject: switching array pointers query
- Date: Sun, 31 Dec 1995 16:48:23 GMT
- Message-ID: <95123120361029516@tglbbs.com>
- Organization: TGL BBS 3 Nodes of Fun 212-974-3925, 212-765-2524, 212-541-5596
- Distribution: world
-
- My struggle with arrays of pointers and such not continues, and here's
- an example of my difficulties. Below is a bit of code that works, after
- trying various ways that didn't work. However, it doesn't do what I
- want quite the way I intended. I have an array of pointers to
- structures, and wish to simply reverse the order of the array. What I
- *want* is to simply change what the pointers point to, that is, the
- first pointer points to what begins as the last element of the array,
- the last points to the first, and so on. But I couldn't get that, and
- you see below that I am simply moving the information in the last
- element into where the first pointer is pointing etc. Since it
- does work, it might seem like I could just not worry about it. But I'm
- hoping seeing how this should be done might give me an understanding
- breakthrough on this whole pointer to array thing that drives me crazy.
-
- Thanks to all who help.
-
- void
- ReverseFiles( struct find_t **files, int numberfiles )
- {
- int i, h;
- struct find_t temp;
-
- for( i = 0, h = numberfiles - 1; i < h; i++, h-- ) {
- temp = (*files)[i];
- (*files)[i] = (*files)[h];
- (*files)[h] = temp;
- }
- }
-